import React, { Component } from 'react'

// react-loadable原理
const Loadable = ({loader, loading: Loading}) => {
   return class loadable extends Component {
        state = {
            loadComponent: null
        }
        componentDidMount() {
            loader().then(response=> {
                this.setState({loadComponent: response.default})
            })
        }
        
        render() {
            const {LoadedComponent} = this.state
            return (
                    LoadedComponent ? 
                    <LoadedComponent /> :
                    <Loading />
            )
        }
    }
}

export default Loadable
